package com.sunk.springcloud.controller;

import com.sunk.springcloud.entities.CommonResult;
import com.sunk.springcloud.entities.Payment;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @Auther: Sunk
 * @Date: 2020/3/16 10:19
 * @Description:
 */
@RestController
public class PaymentController {
    @Value("${server.port}")
    private String serverPort;

    @GetMapping("/payment/nacos/{id}")
    public String getPayment(@PathVariable("id") Integer id){
        return"nacos registry,serverPort:" + serverPort +"\t id:"+id;

    }

    public static HashMap<Long, Payment> hashMap=new HashMap<>();
    static {
        hashMap.put(1l,new Payment(1l,"asdasds"));
        hashMap.put(2l,new Payment(2l,"asdasdasds"));
        hashMap.put(2l,new Payment(2l,"asdazxczcxzcxsds"));
    }

    @GetMapping("/paymentSQL/{id}")
    public CommonResult paymentSQL(@PathVariable("id")Long id){
        Payment payment = hashMap.get(id);
        CommonResult<Payment> result=new CommonResult<>(200,"from db,port:"+serverPort,payment);
        return result;
    }

}
